/**
 * 给定一个黑白二色的数组，要求只刷一段就全白，
 * 问最少刷的长度
 */
#include <bits/stdc++.h>
using namespace std;

using llt = long long;
using vi = vector<int>;

int N;
string S;

int proc(){
    int k = 0;
    while(k < N and S[k] == 'W') ++k;
    if(k == N) return 0;

    int o = N - 1;
    while(o >= 0 and S[o] == 'W') --o;
    assert(k <= o);

    return o - k + 1;
}

int main(){
#ifndef ONLINE_JUDGE
    freopen("z.txt", "r", stdin);
#endif
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int nofkase = 1; 
    cin >> nofkase;
    while(nofkase--){
        cin >> N >> S;
        cout << proc() << "\n";      
    }
    return 0;
}